Use input selections to limit the query
This query in its current state will return all sales records for all employees. However the query is to be limited by the input selections entered on the form. Therefore, a WHERE clause is required to limit the query to selected employees within a date range.
Within the DataBlock Designer, double-click on the object that was just created which contains the results of the query. Then click the hardhat/hammer (Edit Visual Design) icon to bring up the Build Query dialog box. Click the “Conditional Fields (WHERE) tab where you can create the required WHERE clause.
The WHERE clause should only obtain records where:
- The employee last name selected = the employee last name in the database and,
- The employee first name selected = the employee first name in the database and,
- The sale date is greater than or equal to the start date selected and,
- The sale date is less than or equal to the end date selected
The above limits the query to the selections entered by the person executing the report. Each of the above conditions will be entered under the Conditional Fields tab.
The condition for 'Employees.last_name' will be created first. If you already have the Build Query open, then skip to Step 3.
- Double-click on the multi-column listbox, that we edited in the previous exercise, to launch the Choice Entry window.
- Click Edit Visual Design () to launch the Build Query window.
- Select the Conditional Fields (WHERE) tab.
- Double-click the 'last_name' field in the 'Employees' table to auto-populate the first three fields.
- Click inside the Condition field, then click the ellipsis button that appears inside the field.
- Insert an Equals sign (=).
- Click the insert variable icon to display the variables that exist within the DataBlock.
- Select 'last_name'. Recall that EmployeeList is the name of the multi-column list box containing the list of employee names. The two fields within the Employee table are 'last_name' and 'first_name'.
- Click OK to continue.
- Click OK to continue.
The condition for 'last_name' has been created, as shown in the above figure. - Click on the blank field to the right of the field just created and repeat Steps 4 through 10 for the employee first name.
After adding the employee first and last names, we will need to add date conditions using 'sale_date' from the 'Orders' table, and the 'StartDate' and 'EndDate' variables (which were added to the dashboard in a previous exercise).
- Double-click 'sale_date' in the 'Orders' table to auto-populate the and/or, Table, and Field fields.
- Click inside the Condition field, then click the ellipses button that appears inside the field to launch the SQL Editor.
- Enter Greater than or equal to (>=).
- Click the insert variable icon to see the list of available variables.
- Select StartDate from the variable list.
- Repeat from Step 12 to add the condition Less than or equal to the End Date (<= :EndDate) to 'sale_date'.
- Click OK and validate the query.
- Click Finish to complete the design of the WHERE clause and return to the DataBlock Designer.
- Click Save to save your work, then click the Test button to test the dashboard.